package com.community.process._1010.api;

import com.community.process._1010.common.api.CommonResult;
import com.community.process._1010.dao.dto.ProcessIngredientsDTO;
import com.community.process._1010.dao.entity.ProcessIngredients;
import com.community.process._1010.dao.query.ProcessIngredientsQuery;
import com.community.process._1010.service.impl.ProcessIngredientsServiceImpl;
import com.oneadds.lowcode.dto.PageListData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @ClassName ProcessIngredientsController
 * @Description TODO
 * @Author jamesj
 * @Date 2024/9/5 16:57
 */
@RestController
@RequestMapping("admin/ProcessIngredients")
//@Api(tags = { "【Admin - 代理商信息收集表管理】代理商信息收集表管理api" })
public class ProcessIngredientsLowcodeController {
    @Autowired
    ProcessIngredientsServiceImpl processIngredientsService;

    @GetMapping("ProcessIngredients/{id}")
//    @ApiOperation(value = "通过id获取一个代理商信息收集表", produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "GET")
    @ResponseBody
    public CommonResult<ProcessIngredients> getOneProcessIngredients(@PathVariable @NotNull Long id) {
        ProcessIngredients item = processIngredientsService.getById(id);
        return CommonResult.success(item);
    }

    @PostMapping("ProcessIngredients")
//    @ApiOperation(value = "添加一个代理商信息收集表", produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "POST")
    @Transactional
    @ResponseBody
    public CommonResult<ProcessIngredients> addOneProcessIngredients(@RequestBody ProcessIngredients item) {
        processIngredientsService.addOne(item);
        return CommonResult.success(item);
    }


    @PutMapping("ProcessIngredients")
//    @ApiOperation(value = "更新一个代理商信息收集表", produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "PUT")
    @Transactional
    @ResponseBody
    public CommonResult<ProcessIngredients> updateOneProcessIngredients(@RequestBody ProcessIngredients item) {
        processIngredientsService.updateOne(item);
        return CommonResult.success(item);
    }


    @PostMapping("ProcessIngredients/pages")
//    @ApiOperation(value = "获取代理商信息收集表的分页数据", produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "POST")
    @ResponseBody
    public CommonResult<PageListData<ProcessIngredients>> getPagesOfProcessIngredients(@RequestBody ProcessIngredientsQuery query) {
        PageListData<ProcessIngredients> items = processIngredientsService.getPage(query);
        return CommonResult.success(items);
    }

    @PostMapping("ProcessIngredients/options")
//    @ApiOperation(value = "获取代理商信息收集表的下拉列表", produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "POST")
    @ResponseBody
    public CommonResult<PageListData<ProcessIngredientsDTO.ProcessIngredientsBrief>> getOptionsProcessIngredients(@RequestBody ProcessIngredientsQuery query) {
        PageListData<ProcessIngredientsDTO.ProcessIngredientsBrief> items = processIngredientsService.getPageByDto(query, ProcessIngredientsDTO.ProcessIngredientsBrief.class);
        return CommonResult.success(items);
    }

    @DeleteMapping("ProcessIngredients/{id}")
//    @ApiOperation(value = "删除一个代理商信息收集表", produces = MediaType.APPLICATION_JSON_VALUE, httpMethod = "DELETE")
    @Transactional
    @ResponseBody
    public CommonResult<Boolean> deleteOneProcessIngredients(@PathVariable @NotNull Long id) {
        Boolean delete = processIngredientsService.removeById(id);
        return CommonResult.success(delete);
    }
}
